home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5160 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Unable to check callo
  5. Date: 7 Feb 1996 16:40:41 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4fakm9$24f@gail.ripco.com>
  8. NNTP-Posting-Host: foley.ripco.com
  9.  
  10. ramli@sislnews.csc.ti.com (C. S. Ramalingam)
  11. in <4fadmp$t6g@osage.csc.ti.com> asks:
  12.  
  13. >When would using calloc be more appropriate than using malloc ?  Is it true
  14. >that the only use for calloc is in initializing integral values to zero ?
  15. >If so, why was a new function, which appears to have very limited used,
  16. >introduced in the first place ?
  17.  
  18.  
  19. It is extremely rare that I find it useful to use calloc(). If I needed
  20. to initialize a region of all bits zero (not necessarily the same as a
  21. floating-point zero or null pointer), I would use it. There are
  22. instances where this is useful, but functions such as memset(),
  23. memcpy(), memmove(), strcpy(), and strncpy() provide a more general way
  24. to initialize regions of memory without carrying the overhead of doing
  25. that initialization when allocating the space.
  26.  
  27. At the time of K&R1 (1978), the "standard" library had calloc() but
  28. _not_ malloc().  malloc() is a stripped down version of calloc() rather
  29. than calloc() being an augmented malloc().  So calloc() exists in older
  30. C programs that would break if it were not available.
  31.  
  32.                                                                               
  33. --
  34. * Martin Ambuhl       net: mambuhl@ripco.com
  35. * Chicago, IL (USA)    
  36.